import {createStore} from 'redux'
const ADD_GUN='加机关枪'
const REMOVE_GUN='减机关枪'
const ADD_GUN2='加多个个机关枪'
export function  counter(state=10,action) {
    switch (action.type) {
        case ADD_GUN:
            return state+1;
        case REMOVE_GUN:
            return state-1;
        case ADD_GUN2:
            return state+action.num;
        default:return state
    }
}
export function addGun() {
    return {type:ADD_GUN}
}
export function addGun2(num) {
    return {num,type:ADD_GUN2}
}
export function removeGun() {
    return {type:REMOVE_GUN}
}
export function addGunTwice(){
    return [{type:ADD_GUN},addGunAsync()]
}
// 延迟添加，拖两天再给
export function addGunAsync(){
    
    // thunk插件的作用，这里可以返回函数，
    return dispatch => {
      setTimeout(() => {
        console.log(1231231)
        // 异步结束后，手动执行dispatch
        dispatch(addGun());
      }, 2000);
    };
  
  }